<%--
  Created by IntelliJ IDEA.
  User: 王志斌
  Date: 2019/2/8
  Time: 0:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String static_path = path + "/static/alpha";
    String x_admin_path = path + "/static/X-admin-2.3";
%>
<html>
<head>
    <!-- X-admin -->
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="<%=x_admin_path%>/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="<%=x_admin_path%>/css/font.css">
    <link rel="stylesheet" href="<%=x_admin_path%>/css/xadmin.css">
    <script type="text/javascript" src="<%=x_admin_path%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=x_admin_path%>/js/xadmin.js"></script>
</head>
<body>
<%-- 修改一级类别 --%>
<c:if test="${requestScope.type eq 2}">
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="parentName" class="layui-form-label">
                    <span class="x-red">*</span>类别名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="parentName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${requestScope.postTypeInfo.name}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="updateSub2" lay-submit="">
                    修改
                </button>
            </div>
        </form>
    </div>
</c:if>

<%-- 修改二级类别 --%>
<c:if test="${requestScope.type eq 3}">
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="parentName" class="layui-form-label">
                    <span class="x-red">*</span>类别名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="parentName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${requestScope.postTypeInfo.name}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="parentVal" class="layui-form-label">上级类型
                </label>
                <div class="layui-input-inline">
                    <select id="parentVal" class="valid" lay-search lay-filter="allPostType">
                        <option value="">请选择</option>
                        <c:forEach items="${requestScope.postTypeList}" var="list">
                            <option value="${list.id}"
                                    <c:if test="${requestScope.postTypeInfo.prentId eq list.id}">
                                        selected="selected"
                                    </c:if>
                            >${list.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="updateSub3" lay-submit="">
                    修改
                </button>
            </div>
        </form>
    </div>
</c:if>

<script>
    layui.use('form', function(){
        var layer = layui.layer
            ,form = layui.form;

        //修改一级类别监听提交
        form.on('submit(updateSub2)', function(data){
            //发异步
            layer.alert("修改成功", {icon: 6},function () {
                var name = $("#parentName").val();

                $.ajax({
                    url:"<%=path%>/manage/department/post_management/update",
                    type:"post",
                    data:{type:2,id:${requestScope.postTypeInfo.id},name:name},
                });

                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
        });

        //修改二级类别监听提交
        form.on('submit(updateSub3)', function(data){
            //发异步
            layer.alert("修改成功", {icon: 6},function () {
                var parentName = $("#parentName").val();
                var parentVal = $("#parentVal").val();

                $.ajax({
                    url:"<%=path%>/manage/department/post_management/update",
                    type:"post",
                    data:{name:parentName,prentId:parentVal,id:${requestScope.postTypeInfo.id},type:3},
                });

                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
        });

    });



</script>

</body>
</html>
